package pattern1;

import java.util.Scanner;

/**
 * p1
 * 简单工厂模式
 * 通过简单工厂模式实现一个计算器
 *
 * @author wdl
 */
public class SimpleFactory {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入数字A");
        double numberA = input.nextDouble();

        System.out.println("请选择运算符(+,-,*,/)：");
        String operate = input.next();

        System.out.println("请输入数字B:");
        double numberB = input.nextDouble();
        System.out.print(numberA + operate + numberB + "=");

        try {
            AbstractOperation operation = OperationFactory.createOperation(operate);
            operation.numberA = numberA;
            operation.numberB = numberB;
            double result = operation.getResult();
            System.out.print(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}


